package service

import (
	"a-app/dao"
	"a-app/domain/entity"
	dom "a-common/domain"
	"a-common/utils/excel"

	"sync"

	"github.com/xuri/excelize/v2"
)

var (
	appBalanceServiceTemp *AppBalanceService
	appBalanceDao         = dao.NewAppBalanceDao()
	appBalanceServiceOnce sync.Once
)

type AppBalanceService struct{}

func NewAppBalanceService() *AppBalanceService {
	appBalanceServiceOnce.Do(func() {
		appBalanceServiceTemp = &AppBalanceService{}
	})
	return appBalanceServiceTemp
}

// List 分页
func (m *AppBalanceService) List(args *entity.AppBalanceDto) (dom.PageVo, error) {
	return appBalanceDao.List(args, false)
}

// Get 查
func (m *AppBalanceService) Get(id string) (entity.AppBalanceVo, error) {
	return appBalanceDao.Get(id)
}

// Del 删
func (m *AppBalanceService) Del(ids string) (int64, error) {
	return appBalanceDao.Del(ids)
}

// Add 增
func (m *AppBalanceService) Add(args *entity.AppBalanceDto) (int64, error) {
	return appBalanceDao.Add(args)
}

// Edit 改
func (m *AppBalanceService) Edit(args *entity.AppBalanceDto) (int64, error) {
	return appBalanceDao.Edit(args)
}

// Export 导出
func (m *AppBalanceService) Export(args *entity.AppBalanceDto) (*excelize.File, error) {
	pageVo, err := appBalanceDao.List(args, true)
	if err != nil {
		return nil, err
	}
	return excel.NormalDynamicExport(pageVo.Rows, "Sheet1", "余额信息表", "", true, false, map[string]string{})
}
